;
(function() {

  'use strict';

  angular.module('services.dataQualityMng')
    .factory('dataQualityReportFactory', dataQualityReportFactory);

  function dataQualityReportFactory(Restangular) {
    return {
      query: query,
      initChart:initChart
    };

    function query(params, callback) {
      Restangular.all('sas/dataManager/dataQuality/dataMonitor/report/query').post(params).then(callback);
    }
    //初始化图表（柱状图）
    function initChart(data, title) {
      var dataArr = ['完整性分数', '准确性分数', '时效性分数', '综合评分'];
      var businessNames = [];
      var wzxscores = [];
      var zqxscores = [];
      var sxxscores = [];
      var avgscores = [];
      angular.forEach(data, function(b) {
        businessNames.push(b.businessName);
        wzxscores.push(b.wzxscore);
        zqxscores.push(b.zqxscore);
        sxxscores.push(b.sxxscore);
        avgscores.push(b.avgscore);
      });
      var dataStyle = {
        normal: {
          label: {
            show: true,
            position: 'insideLeft',
            formatter: '{c}'
          }
        }
      };

      return {
        title: {
          text: title,
          x: 'center',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          },
          formatter: '{b}<br/>{a0}:{c0}<br/>{a1}:{c1}<br/>{a2}:{c2}<br/>{a3}:{c3}'
        },
        legend: {
          data: dataArr,
          y: 55,
          itemGap: document.getElementById('reportChart').offsetWidth / 8
        },
        grid: {
          y: 80,
          y2: 30
        },
        xAxis: [{
          type: 'value',
          position: 'top',
          axisLabel: {
            show: false
          }
        }],
        yAxis: [{
          type: 'category',
          data: businessNames
        }],
        series: [{
          name: dataArr[0],
          type: 'bar',
          stack: '总量',
          itemStyle: dataStyle,
          data: wzxscores
        }, {
          name: dataArr[1],
          type: 'bar',
          stack: '总量',
          itemStyle: dataStyle,
          data: zqxscores
        }, {
          name: dataArr[2],
          type: 'bar',
          stack: '总量',
          itemStyle: dataStyle,
          data: sxxscores
        }, {
          name: dataArr[3],
          type: 'bar',
          stack: '总量',
          itemStyle: dataStyle,
          data: avgscores
        }, ]
      };
    }
  }

})();